package main

import (
	"gorm.io/driver/mysql"
	"gorm.io/gen"
	"gorm.io/gorm"
	"os"
)

// Dynamic SQL
type Querier interface {
	FilterWithNameAndRole(name, role string) ([]gen.T, error)
}

var (
	dir, _ = os.Getwd()
)

func main() {
	g := gen.NewGenerator(gen.Config{
		OutPath:      dir + "\\mvc\\dao\\query",
		ModelPkgPath: dir + "\\mvc\\dao\\model",
		Mode:         gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
	})

	gormdb, _ := gorm.Open(mysql.Open("root:@(127.0.0.1:3306)/db_poem?charset=utf8mb4&parseTime=True&loc=Local"))
	g.UseDB(gormdb) // reuse your gorm db

	// Generate basic type-safe DAO API for struct `model.User` following conventions
	//g.ApplyBasic(model.User{})

	// Generate Type Safe API with Dynamic SQL defined on Querier interface for `model.User` and `model.Company`
	g.ApplyInterface(func(Querier) {})

	g.ApplyBasic(
		// Generate structs from all tables of current database
		g.GenerateAllTable()...,
	)
	// Generate the code
	g.Execute()
}
